<?php
require_once '../../includefiles.php';
require_once "../../model/testimonials.php";
require_once '../../model/users.php';
require_once '../../model/email.php';
require_once "../../includes/classes/paging_htacess.php";
require_once '../../redirect.php';

## creating objects of required models
$userObj 		= new Model_Users();
$testimonialObj = new Model_Testimonial();

checkUserLogin();

$userId =$_SESSION['getbids_id'];

## When user wants to delete the testimonial
if($_GET['id1'] == 'delete' && $_GET['id2']!='')
{
	$testimonialId = base64_decode($_GET['id2']);
	$testimonialObj->deleteTestimonialById($testimonialId);
	$_SESSION['msg'] = "<div class='success_msg'style='margin-top:5px;margin-bottom: 20px;'><span>Testimonial deleted successfully !</span></div>";
	header("Location:".SITE_URL."/testimonials/mytestimonials");
	exit;
}




## for pagination
	$page = $_GET['id1'];
	if(!isset($_GET['id1']))
	$page = 1;
	else
	$page = $page;
	
## limit per pag 
$tetsimonialPerPage =10;
$StartRow = $tetsimonialPerPage  * ($page-1);
## Getting all testimonials from database according to user



$testimonialArray  = $testimonialObj->testimonialsAccordingToUserId($userId,'','',false);
$totalCount        = count($testimonialArray);
$smarty -> assign("recordsFound",$totalCount);

$res = $testimonialObj->testimonialsAccordingToUserId($userId,$tetsimonialPerPage,$StartRow,true);
$show = 1;
$total_pages = ceil($totalCount / $tetsimonialPerPage);
	if($total_pages > 1)
	$smarty -> assign("showpgnation","yes");
	$showing    = !isset($_GET["id1"]) ? 1 : $page;
	
	## it shoould be file name 
	$firstlink  = "mytestimonials/";
	
	$baselink   = $firstlink;
	if($total_pages!=0)
		$pagenation = pagination($total_pages, $show, $showing, $firstlink, $baselink, "", "testimonials");
	$smarty -> assign("pagenation", $pagenation);
	$smarty -> assign("page", $page);
	//
	$smarty->assign("testimonialArray", $res);
	
/*===========================================================================*/
	$userDetail = $userObj->getUserDetailsByUserId($userId);
	$smarty->assign("userDetArray", $userDetail);	
	
/*===========================================================================*/	


if($_SESSION['msg']){
		$smarty->assign("msg", $_SESSION['msg']);
		unset($_SESSION['msg']);
}


$active ="myaccount";
$smarty->assign('active',$active);
$subactive ="testimonials";
$smarty->assign('subactive',$subactive);
$smarty->assign('mainmenu',"5");

$smarty->display(TEMPLATEDIR . 'modules/testimonial/mytestimonials.tpl');
?>